package org.dongan.iot.common.domain;

import java.util.HashMap;
import java.util.Map;

public class Result extends HashMap<String, Object> {

	private static final long serialVersionUID = 1L;

	public Result() {
		put("code", 0);
	}

	public static Result error() {
		return error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
	}

	public static Result error(String msg) {
		return error(ResultEnum.UNKONW_ERROR.getCode(), msg);
	}

	public static Result error(int code, String msg) {
		Result result = new Result();
		result.put("code", code);
		result.put("msg", msg);
		return result;
	}

	public static Result error(ResultEnum resultEnum) {
		Result result = new Result();
		result.put("code", resultEnum.getCode());
		result.put("msg", resultEnum.getMsg());
		return result;
	}
	

	public static Result ok(Object msg) {
		Result result = new Result();
		result.put("msg", msg);
		return result;
	}

	public static Result ok(Map<String, Object> map) {
		Result result = new Result();
		result.putAll(map);
		return result;
	}

	public static Result ok() {
		return new Result();
	}

	public Result put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}